<?php

namespace app\common\model;

use EasyWeChat\Factory;
use think\Exception;
use think\Model;

/**
 * 邮箱验证码
 */
class DistrictsModel extends Model
{
    protected $name = 'districts';

    protected $tag = ['company','join','cases','track'];
    public function getDetail($param){
        if(!in_array($param['tag'],$this->tag)){
            return ['code' => 201, 'msg' => '参数错误'];
        }

        $detail = self::where(['tag' => $param['tag']])->find();

        $detail['content'] = $this->get_img_thumb_url($detail['content'],config('app.api_url'));

        return ['code' => 200, 'msg' => '获取成功','data' => $detail];
    }

    public function get_img_thumb_url($content = "", $suffix = "")
    {
        $pregRule = "/<[img|IMG].*?src=[\'|\"](.*?(?:[\.jpg|\.jpeg|\.png|\.gif|\.bmp]))[\'|\"].*?[\/]?>/";
        $content = preg_replace($pregRule, '<img src="' . $suffix . '${1}" style="max-width:100%">', $content);
        return $content;
    }

}
